package oop.ex3.tester;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

public class Tester2 {
	public static void main(String[] args) throws UnknownHostException, IOException {
		Socket socket = new Socket(InetAddress.getLocalHost().getHostAddress(), 2000);
		DataInputStream input = new DataInputStream(socket.getInputStream());
		DataOutputStream output = new DataOutputStream(socket.getOutputStream());
		output.writeUTF("BEGIN");
		output.writeUTF(InetAddress.getLocalHost().getHostAddress());
		output.writeInt(2060);
		output.writeUTF("END");
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		output.writeUTF("CONTAINFILE");
		output.writeUTF("gagaga");
		output.writeUTF("END");
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		output.writeUTF("CONTAINFILE");
		output.writeUTF("suckmycock");
		output.writeUTF("END");
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		output.writeUTF("CONTAINFILE");
		output.writeUTF("dada");
		output.writeUTF("END");
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		output.writeUTF("ENDLIST");
		output.writeUTF("END");
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		output.writeUTF("CONTAINNAMESERVER");
		output.writeUTF(InetAddress.getLocalHost().getHostAddress());
		output.writeInt(2000);
		output.writeUTF("END");
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		output.writeUTF("ENDLIST");
		output.writeUTF("END");
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		output.writeUTF("CONTAINFILE");
		output.writeUTF("THISmYlIFE.TXT");
		output.writeUTF("END");
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		output.writeUTF("WANTALLFILES");
		output.writeUTF("END");
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		output.writeUTF("DONTCONTAINFILE");
		output.writeUTF("THISmYlIFE.TXT");
		output.writeUTF("END");
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		output.writeUTF("WANTALLFILES");
		output.writeUTF("END");
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		output.writeUTF("WANTFILE");
		output.writeUTF("suckmycock");
		output.writeUTF("END");
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		System.out.println(input.readInt());
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		output.writeUTF("WANTSERVERS");
		output.writeUTF("END");
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		System.out.println(input.readInt());
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		output.writeUTF("ENDSESSION");
		output.writeUTF("END");
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		
		socket = new Socket(InetAddress.getLocalHost().getHostAddress(), 2000);
		input = new DataInputStream(socket.getInputStream());
		output = new DataOutputStream(socket.getOutputStream());
		output.writeUTF("BEGIN");
		output.writeUTF(InetAddress.getLocalHost().getHostAddress());
		output.writeInt(2060);
		output.writeUTF("END");
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		output.writeUTF("WANTALLFILES");
		output.writeUTF("END");
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		output.writeUTF("WANTSERVERS");
		output.writeUTF("END");
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		System.out.println(input.readInt());
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		output.writeUTF("GOAWAY");
		output.writeUTF("END");
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		output.writeUTF("ENDSESSION");
		output.writeUTF("END");
		System.out.println(input.readUTF());
		System.out.println(input.readUTF());
		input.close();
		output.close();
		socket.close();
	}
}
